/**
 * 酒秀
 * 9elephas.com
 */
import React, {Component, PropTypes} from 'react';
import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
} from 'react-native';
import JiuProList from '../share/JiuProList';
import {request} from '../apis/net/Net';
import {SCREEN_WIDTH, SCREEN_HEIGHT} from '../config'

const limitNum: int = 20;
export default class Pictures extends Component {
    static navigationOptions = {
        title: '拍照'
    };

    constructor(props) {
        super(props)

    }

    selectPage: number = 1;

    render() {
        return (
            <View style={{flex:1}}>
                <Text>拍照</Text>
                <JiuProList style={{backgroundColor:'red',width:SCREEN_WIDTH,height:SCREEN_HEIGHT-400}}
                            renderEmptyData={
                        () => {
                            return(   <View
                                style={{ height: SCREEN_HEIGHT * 2 / 3, alignItems: 'center', justifyContent: 'center', width: SCREEN_WIDTH,backgroundColor:'orange' }}>
                                <Text
                                    style={{ fontSize: 14, color: '#f1f1f1', marginTop: 20 }}>{'暂无数据'}</Text>
                            </View>
                         )
                        }
                    }
                            ref={this.listRef.bind(this)}
                            itemHeight={90}
                            renderItem={this.renderRow.bind(this)}
                            initialNumToRender={limitNum}
                            onRefresh={this.onRefresh.bind(this)}
                            onEndReached={this.onEndReached.bind(this)}>
                    >
                </JiuProList>
                <Text>上课</Text>
            </View>
        )
    }

    componentDidMount() {
        this.onRefresh();
    }

    renderRow(rowData: object, index: number) {
        return (
            <ListItem data={rowData}></ListItem>
        )
    }

    onRefresh() {
        this.selectPage = 1;
        let params: Object = {
            location: '310109',
            page: 1,
            limit: limitNum
        };
        this.list.setRefreshing(true);
        request('/app/user/searchBySql2', (responseData: Object)=> {
            if (responseData.ret == 1) {
                this.list.setData(responseData.list);
                this.amount = responseData.count;
            }
        }, params, null, true, false);

    }

    onEndReached() {
        console.log("=====onInfinite========")
        if (this.selectPage * limitNum >= this.amount) {
            return;
        }
        let params: Object = {
            location: '310109',
            page: this.selectPage + 1,
            limit: limitNum
        };
        this.list.setRefreshing(true);
        request('/app/user/searchBySql2', (responseData: Object)=> {
            if (responseData.ret == 1) {
                this.list.setData(responseData.list);
                this.amount = responseData.count;
                this.selectPage++;
            }
        }, params, null, true, false);

    }

    listRef(node) {
        this.list = node;
    }
}
class ListItem extends Component {
    static propTypes = {
        data: PropTypes.object,
    }

    constructor(props) {
        super(props);
    }

    render() {
        // console.log("ListItem", this.props.data);
        return (<View>
            <Text style={{height:90,backgroundColor:'green'}}>{this.props.data.company.name}</Text>
        </View>)
    }
}
const styles = StyleSheet.create({
    container: {
        width: 100,
        height: 100,
        borderRadius: 10
    }
})



